import Home from '@/pages/Home'
import Login from '@/pages/Login'
import Search from '@/pages/Search'
import Register from '@/pages/Register'
import Detail from '@/pages/Detail'
import AddCartSuccess from '@/pages/AddCartSuccess'
import ShopCart from '@/pages/ShopCart'
import Trade from'@/pages/Trade'
import Pay from '@/pages/Pay'
import PaySuccess from '@/pages/PaySuccess'
import Center from "@/pages/Center"
import MyOrder from '@/pages/Center/MyOrder'
import GroupOrder from '@/pages/Center/GroupOrder'
export default [
    {
        path:'/home',
        // 路由懒加载  路由只会加载一次  第二次访问不会重新加载   只在访问的时候加载  一般的是你跳转不跳转都会加载
        component:()=>import('@/pages/Home'),
        meta:{
            show:true
        }
    },
    {
        path:'/login',
        component:Login,
        meta:{
            show:false
        }
    },
    {
        name:'search',
        path:'/search/:keyword?',
        component:Search,
        meta:{
            show:true
        },
        // props 的传参方式
        // 布尔值方式  只能传params的参数
        // props:true
        // 对象的方式  
        // props:{
        //     a:'2'
        // }
        props:(route)=>{
            return {
                keyword:route.query.keyword
            }
        }
    },
    {
        path:'/register',
        component:Register,
        meta:{
            show:false
        }
    },
    // 详情页路由
    {
        path:'/detail/:skuId',
        component:Detail,
        meta:{
            show:true
        }
    },
    {
        path:'/',
        redirect:'/home'
    },
    // 添加购物车的路由组件
    {
        path:'/addcartsuccess',
        component:AddCartSuccess,
        meta:{
            show:true
        },
        name:"addcartsuccess"
    },
    // 查询结账信息的页面路由
    {
        path:'/shopcart',
        component:ShopCart,
        // 路由元信息
        meta:{
            show:true
        }
    },
    // 交易路由
    // 要从购物车过来  不是购物车就不能进去交易页
    {
        path:'/trade',
        component:Trade,
        meta:{
            show:true
        },
        // 进入之前
        beforeEnter: (to, from, next) => {
            // console.log(from.path);
            if(from.path == '/shopcart'){
                next();
            }else{
                // 还是再该页面
                next(false);
            }
        }
    },
    // 提交订单
    {
        path:'/pay',
        component:Pay,
        meta:{show:true},
        beforeEnter: (to, from, next) => {
            if(from.path == "/trade"){
                next();
            }else{
                next(false)
            }
        }
    },
    // 支付成功的页面路由
    {
        path:'/paySuccess',
        component:PaySuccess,
        meta:{
            show:true
        }
    },
    // 查看支付页面
    {
        path:'/center',
        component:Center,
        meta:{show:true},
        // 二级路由
        children:[
            {
                path:'myorder',
                component:MyOrder
            },
            {
                path:'grouporder',
                component:GroupOrder
            },
            {
                path:'/center',
                redirect:'/center/myorder'
            }
        ]
    }
    
]